package org.emergency.framework.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.emergency.framework.constant.ModelConstant;

@Entity
@Table(name = "TB_USER", catalog = ModelConstant.DB_CATALOG)
public class TbUser implements Serializable {
	private static final long serialVersionUID = 1L;

	public static String USERTYPE_INTERNAL = "Internal";
	public static String USERTYPE_EXTERNAL = "External";

	@Id
	@Column(name = "TB_USER_ID", unique = true, nullable = false,length=ModelConstant.STRING_LENGHT_id)
	private String tbUserId;// 用户 id

	@Column(name = "name", length = ModelConstant.STRING_LENGHT_1,nullable = false)
	private String name;// 用户名

	@Column(name = "password", length = ModelConstant.STRING_LENGHT_1)
	private String password;// 用户密码

	@Column(name = "userType", length = ModelConstant.STRING_LENGHT_1)
	private String userType;// 用户类型

	/**
	 * 帐号是否过期，暂没有用
	 */
	@Column(name = "isAccountNonExpired",nullable = false)
	private boolean isAccountNonExpired;

	/**
	 * 是否可用，用作删除标记位
	 */
	@Column(name = "isEnabled",nullable = false)
	private boolean isEnabled;
	
	/**
	 * 最后登陆时间
	 */
	@Column(name="lastLoginTime",nullable=true)
	private Date lastLoginTime;
	
	/**
	 * 手机
	 */
	@Column(name="mobilephone",length=ModelConstant.STRING_LENGHT_1)
	private String mobilephone;
	
	/**
	 * 电话
	 */
	@Column(name="telephone",nullable=true)
	private String telephone;
	
	/**
	 *  email
	 */
	@Column(name="email",nullable=true,length=ModelConstant.STRING_LENGHT_1)
	private String email;
	
	/**
	 * 传真
	 */
	@Column(name="fax",nullable=true,length=ModelConstant.STRING_LENGHT_1)
	private String fax;

	
	//以下为备用字段
	@Column(name="a",nullable=true,length=ModelConstant.STRING_LENGHT_1)
	private String a;
	
	@Column(name="b",nullable=true,length=ModelConstant.STRING_LENGHT_1)
	private String b;
	
	@Column(name="c",nullable=true,length=ModelConstant.STRING_LENGHT_1)
	private String c;
	
	@Column(name="e",nullable=true,length=ModelConstant.STRING_LENGHT_1)
	private String e;
	
	@Column(name="d",nullable=true,length=ModelConstant.STRING_LENGHT_1)
	private String d;
	//以上为备用字段
	
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "tbUser")
	private Set<TbUserRoleEntity> tbUserRoleEntities = new HashSet<TbUserRoleEntity>(
			0);//和中间表一对多

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "tbUser")
	private Set<TbUserDepartment> tbUserDepartment = new HashSet<TbUserDepartment>(
			0);//和用户部门中间表一对多

//	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "users")
//	private Set<TbDepartment> deps = new HashSet<TbDepartment>(0);//用户部门
	
	public TbUser() {
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((tbUserId == null) ? 0 : tbUserId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TbUser other = (TbUser) obj;
		if (tbUserId == null) {
			if (other.tbUserId != null)
				return false;
		} else if (!tbUserId.equals(other.tbUserId))
			return false;
		return true;
	}

	public String getTbUserId() {
		return tbUserId;
	}

	public void setTbUserId(String tbUserId) {
		this.tbUserId = tbUserId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<TbUserRoleEntity> getTbUserRoleEntities() {
		return tbUserRoleEntities;
	}

	public void setTbUserRoleEntities(Set<TbUserRoleEntity> tbUserRoleEntities) {
		this.tbUserRoleEntities = tbUserRoleEntities;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}

	public boolean isAccountNonExpired() {
		return isAccountNonExpired;
	}

	public void setAccountNonExpired(boolean isAccountNonExpired) {
		this.isAccountNonExpired = isAccountNonExpired;
	}

	public boolean isEnabled() {
		return isEnabled;
	}

	public void setEnabled(boolean isEnabled) {
		this.isEnabled = isEnabled;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public static String getUSERTYPE_INTERNAL() {
		return USERTYPE_INTERNAL;
	}

	public static void setUSERTYPE_INTERNAL(String uSERTYPEINTERNAL) {
		USERTYPE_INTERNAL = uSERTYPEINTERNAL;
	}

	public static String getUSERTYPE_EXTERNAL() {
		return USERTYPE_EXTERNAL;
	}

	public static void setUSERTYPE_EXTERNAL(String uSERTYPEEXTERNAL) {
		USERTYPE_EXTERNAL = uSERTYPEEXTERNAL;
	}

	public Set<TbUserDepartment> getTbUserDepartment() {
		return tbUserDepartment;
	}

	public void setTbUserDepartment(Set<TbUserDepartment> tbUserDepartment) {
		this.tbUserDepartment = tbUserDepartment;
	}

	public Date getLastLoginTime() {
		return lastLoginTime;
	}

	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	public String getMobilephone() {
		return mobilephone;
	}

	public void setMobilephone(String mobilephone) {
		this.mobilephone = mobilephone;
	}

	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getA() {
		return a;
	}

	public void setA(String a) {
		this.a = a;
	}

	public String getB() {
		return b;
	}

	public void setB(String b) {
		this.b = b;
	}

	public String getC() {
		return c;
	}

	public void setC(String c) {
		this.c = c;
	}

	public String getE() {
		return e;
	}

	public void setE(String e) {
		this.e = e;
	}

	public String getD() {
		return d;
	}

	public void setD(String d) {
		this.d = d;
	}
	
}
